package com.huawei.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huawei.crm.domain.Systemdictionary;
import com.huawei.crm.mapper.SystemdictionaryMapper;
import com.huawei.crm.query.QueryObject;
import com.huawei.crm.service.ISystemdictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SystemdictionaryServiceImpl extends AbstractService<SystemdictionaryMapper, Systemdictionary, Long>
        implements ISystemdictionaryService {

    @Autowired
    private SystemdictionaryMapper mapper;

    @Override
    public void saveOrUpdateS(Systemdictionary isd) {
        if (isd.getId() == null) {
            mapper.insert(isd);
        } else {
            mapper.updateByPrimaryKey(isd);
        }
    }

    @Override
    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Systemdictionary get(Long id) {
        return mapper.selectPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Systemdictionary> listAll() {
        return mapper.selectAll();
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Systemdictionary> query(QueryObject qo) {
        // 告诉mybatis需要去哪里拼接sql
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Systemdictionary> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }

}
